package com.azzan.springcloud2021.controller;

import com.azzan.springcloud.entities.CommomResult;
import com.azzan.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author Azzan
 * @data 2021/7/22 10:10
 */
@RestController
@Slf4j
public class OrderController {

//    public static final String PAYMENT_URL = "http://localhost:8001";
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";


    @Resource
    private RestTemplate restTemplate;

    @PostMapping(value = "/consumer/payment/create")
    public CommomResult<Payment> create(@RequestBody Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,CommomResult.class);
//        log.info("插入结果"+result);
//        if (result>0){
//            return new CommomResult(200,"数据插入成功", result);
//        }else {
//            return new CommomResult(400,"数据插入失败",null);
//        }

    }
    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommomResult<Payment> getPaymentById(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommomResult.class);
//        Payment payment = paymentService.getPaymentById(id);
//        if (payment != null){
//            return  new CommomResult(200,"查询成功",payment);
//        }else {
//            return  new CommomResult(400,"查询失败+id="+id,null);
//
//        }
    }
}
